package com.example.springsession.controller;

import com.example.springsession.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.util.StringUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class HelloCo {
    //set by name
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }

    @Resource
    UserService userService;


    @RequestMapping("/hello")
    public String hello(HttpServletRequest request) {
        String userId = (String) request.getSession().getAttribute("userId");
        if (StringUtils.isEmpty(userId)) {
            log.info("用户session_id为空！");
            request.getSession().setAttribute("userId", "001_lxf");
        } else {
            log.info("用户session_id:" + userId);
        }

        return userId + "ssss   " + request.getSession().getId();
    }

    @RequestMapping("/get")
    public String get(HttpServletRequest request) {
        System.out.println(userService.findAll());
        return "ok";
    }
}
